import Vue from 'vue'
import Vuex from 'vuex'
import axios from '../config/axios.js'

Vue.use(Vuex)
    //Vuex是vue的全局数据管理器
export default new Vuex.Store({
    state: {
        num: 1,
        list: []
    },
    mutations: {
        addNum(state, n) {
            console.log(state);
            state.num += n
        },
        setList(state, data) {
            state.list = data
        }
    },
    actions: {
        getList(vuex) {
            axios.get('/shopCarList').then(res => {
                vuex.commit('setList', res.data)
            })
        }
    },
    modules: {}
})